<extend name="Public/base"/>
<block name='style'>
    <!-- BEGIN PAGE LEVEL STYLES -->
    <link rel="stylesheet" type="text/css" href="__ASSETS__/global/plugins/select2/select2.css"/>
    <link rel="stylesheet" type="text/css" href="__ASSETS__/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.css"/>
    <!-- END PAGE LEVEL STYLES -->
</block>
<block name="body">


    <div class="col-md-12">
        <!-- BEGIN EXAMPLE TABLE PORTLET-->
        <div class="portlet box grey-cascade">
            <div class="portlet-title">
                <div class="caption">
                    <i class="fa fa-globe"></i>Managed Table
                </div>
                <div class="tools">
                    <a href="javascript:;" class="collapse">
                    </a>
                    <a href="#portlet-config" data-toggle="modal" class="config">
                    </a>
                    <a href="javascript:;" class="reload">
                    </a>
                    <a href="javascript:;" class="remove">
                    </a>
                </div>
            </div>
            <div class="portlet-body">
                <div class="table-toolbar">
                    <div class="row">
                        <div class="col-md-6">

                            <button class="btn green fa fa-plus document_add" type="button" 
                                    url="{:U('article/add',array('cate_id'=>$cate_id,'pid'=>I('pid',0),'model_id'=>$model[0],'group_id'=>$group_id))}">
                                增加 
                            </button>
                            <button class="btn blue fa fa-edit document_edit" type="button" url="http://www.baidu.com">
                                编辑 
                            </button>
                            <button class="btn red fa fa-times document_del" type="button" url="http://www.baidu.com">
                                删除
                            </button>                                        
                            <div class="btn-group open">
                                <button data-toggle="dropdown" type="button" class="btn yellow btn-sm dropdown-toggle" aria-expanded="true">
                                    更多 <i class="fa fa-angle-down"></i>
                                </button>
                                <ul role="menu" class="dropdown-menu">
                                    <li>
                                        <a href="#">
                                            Action </a>
                                    </li>
                                    <li>
                                        <a href="#">
                                            Another action </a>
                                    </li>
                                    <li>
                                        <a href="#">
                                            Something else here </a>
                                    </li>
                                    <li class="divider">
                                    </li>
                                    <li>
                                        <a href="#">
                                            Separated link </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <table class="table table-striped table-bordered table-hover" id="sample_1">
                    <thead>
                        <tr>
                            <th class="table-checkbox row-selected">
                                <input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"/>
                            </th>
                    <volist name="list_grids" id="field">
                        <th>{$field.title}</th>
                    </volist>
                    </tr>
                    </thead>
                    <tbody>
                    <volist name="list" key="k" id="data">
                        <tr class="odd gradeX">
                            <td><input class="checkboxes ids" type="checkbox" value="{$data['id']}" name="ids[]"></td>
                        <volist name="list_grids" id="grid">
                            <td>{:get_list_field($data,$grid)}</td>
                        </volist>
                        </tr>
                    </volist>
                    </tbody>
                </table>
            </div>
        </div>
        <!-- END EXAMPLE TABLE PORTLET-->
    </div>

</block>


<block name='script'>
    <script type="text/javascript" src="__ASSETS__/admin/pages/scripts/table-managed.js"></script>
    <script type="text/javascript" src="__ASSETS__/global/plugins/select2/select2.min.js"></script>
    <script type="text/javascript" src="__ASSETS__/global/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="__ASSETS__/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js"></script>
    <script>
        jQuery(document).ready(function () {
            TableManaged.init();
        });


        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var status = $("#sch-sort-txt").attr("data");
            var query = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (status != '') {
                query = 'status=' + status + "&" + query;
            }
            if (url.indexOf('?') > 0) {
                url += '&' + query;
            } else {
                url += '?' + query;
            }
            window.location.href = url;
        });

        /* 状态搜索子菜单 */
        $(".search-form").find(".drop-down").hover(function () {
            $("#sub-sch-menu").removeClass("hidden");
        }, function () {
            $("#sub-sch-menu").addClass("hidden");
        });
        $("#sub-sch-menu li").find("a").each(function () {
            $(this).click(function () {
                var text = $(this).text();
                $("#sch-sort-txt").text(text).attr("data", $(this).attr("value"));
                $("#sub-sch-menu").addClass("hidden");
            })
        });

        //只有一个模型时，点击新增
        $('.document_add').click(function () {
            var url = $(this).attr('url');
            if (url != undefined && url != '') {
                window.location.href = url;
            }
        });

        //点击排序
        $('.list_sort').click(function () {
            var url = $(this).attr('url');
            var ids = $('.ids:checked');
            var param = '';
            if (ids.length > 0) {
                var str = new Array();
                ids.each(function () {
                    str.push($(this).val());
                });
                param = str.join(',');
            }

            if (url != undefined && url != '') {
                window.location.href = url + '/ids/' + param;
            }
        });

        //回车自动提交
        $('.search-form').find('input').keyup(function (event) {
            if (event.keyCode === 13) {
                $("#search").click();
            }
        });

        $('#time-start').datetimepicker({
            format: 'yyyy-mm-dd',
            language: "zh-CN",
            minView: 2,
            autoclose: true
        });

        $('#time-end').datetimepicker({
            format: 'yyyy-mm-dd',
            language: "zh-CN",
            minView: 2,
            autoclose: true
        });
    </script>
</block>